//
//  HHBaseCollectionCell.h
//  Pods
//
//  Created by Basic on 2018/5/23.
//  Copyright © 2018年 zhihan. All rights reserved.
//  UICollectionView - 普通文本 Cell 基类

import UIKit
import Masonry
import BCComConfigKit

open class HHBaseCollectionCell: UICollectionViewCell {
    //MARK: - property
    /// 是否自定义cell属性，默认NO,使用Base里默认样式
    public var isCustom:Bool = false
    /// 选择回调
    public var selectBlock:((UIButton)->())?
    /// 背景图，默认nil，访问属性自动生成
    public var backgroundImgv:UIImageView {
        if let view = _backgroundImgv { return view }
        let view = UIImageView()
        _backgroundImgv = view
        self.contentView.addSubview(view)
        view.mas_makeConstraints{ (make) in
            make?.left.mas_equalTo()(0)
            make?.right.mas_equalTo()(0)
            make?.top.mas_equalTo()(0)
            make?.bottom.mas_equalTo()(0)
        }
        return view
    }
    private var _backgroundImgv:UIImageView?
    /// icon，默认nil，访问属性自动生成
    public var iconImgv:UIImageView {
        if let view = _iconImgv { return view }
        let view = UIImageView()
        self.contentView.addSubview(view)
        view.mas_makeConstraints{ (make) in
            make?.centerX.offset()(0)
            make?.width.mas_equalTo()(43)
            make?.height.mas_equalTo()(43)
        }
        _iconImgv = view
        return view
    }
    private var _iconImgv:UIImageView?
    /// 选中按钮，默认nil，访问属性自动生成
    public var selectedBtn:UIButton {
        if let view = self._selectedBtn { return view }
        let view = UIButton.init(type: .custom)
        _selectedBtn = view
        view.bc_addTouchUp {[weak self] (btn) in
            self?.selectedBtnClick(btn)
        }
        self.contentView.addSubview(view)
        return view
    }
    private var _selectedBtn:UIButton?
    /// 标题 label，默认nil，访问属性自动生成
    public var titleLb:UILabel {
        if let view = _titleLb { return view }
        let view = UILabel()
        view.font = BCComConfig.shared().bcFont()(14)
        view.textColor = BCComConfig.shared().blackColor
        view.textAlignment = NSTextAlignment.center
        self.contentView.addSubview(view)
        view.mas_makeConstraints{ (make) in
//            make?.top.equalTo()(10)
            make?.centerX.offset()(0)
        }
        _titleLb = view
        return view
    }
    private var _titleLb:UILabel?
    /// 描述 label，默认nil，访问属性自动生成
    public var textLb:UILabel {
        if let view = _textLb { return view }
        let view = UILabel()
        view.font = BCComConfig.shared().bcFont()(15)
        view.textColor = BCComConfig.shared().blackColor
        view.textAlignment = NSTextAlignment.center
        self.contentView.addSubview(view)
        view.mas_makeConstraints{ (make) in
//            make?.bottom.offset()(-10)
            make?.centerX.offset()(0)
        }
        _textLb = view
        return view
    }
    private var _textLb:UILabel?
    /// 右侧描述 label，默认nil，访问属性自动生成
    public var detailLab:UILabel {
        if let view = _detailLab { return view }
        let view = UILabel()
        _detailLab = view
        view.font = BCComConfig.shared().bcFont()(12)
        view.textColor = BCComConfig.shared().blackColor
        view.textAlignment = NSTextAlignment.right
        self.contentView.addSubview(view)
        view.mas_makeConstraints{ (make) in
//            make?.bottom.offset()(-10)
            make?.centerX.offset()(0)
            make?.right.mas_equalTo()(-15)
        }
        return view
    }
    private var _detailLab:UILabel?
    /// 右侧分割线，默认nil，访问属性自动生成
    public var rightSplitLb:UILabel {
        if let view = _rightSplitLb { return view }
        let view = UILabel()
        _rightSplitLb = view
        view.backgroundColor = BCComConfig.shared().splitColor
        self.contentView.addSubview(view)
        view.mas_makeConstraints{ (make) in
            make?.right.equalTo()(self.contentView)
            make?.width.equalTo()(0.6)
            make?.top.equalTo()(self.contentView)
            make?.bottom.equalTo()(self.contentView)
        }
        return view
    }
    private var _rightSplitLb:UILabel?
    /// 底部分割线，默认nil，访问属性自动生成
    public var bottomSplitLb:UILabel {
        if let view = _bottomSplitLb { return view }
        let view = UILabel()
        _bottomSplitLb = view
        view.backgroundColor = BCComConfig.shared().splitColor
        self.contentView.addSubview(view)
        view.mas_makeConstraints{ (make) in
            make?.left.mas_equalTo()(0)
            make?.right.mas_equalTo()(0)
            make?.height.mas_equalTo()(0.6)
            make?.bottom.mas_equalTo()(0)
        }
        return view
    }
    private var _bottomSplitLb:UILabel?
    
    //MARK: - event
    ///  选中按钮点击事件
    private func selectedBtnClick(_ sender:UIButton) {
        sender.isSelected = !sender.isSelected
        self.selectBlock?(sender)
    }
}
